// Make coefficient plots for table 3 and table 6/7
// Use estimates from draft/JSresults

clear
clear mata
clear matrix
set maxvar 10000
estimates clear

loc coefplot_events "wneg2 any_rlost_job male_rwidowed fem_rwidowed any_rhosp any_disab any_health3to5"

loc regsave_path output/event_study_regsave

// need to 1) grab estimates for each event-LHS combo 2) add columns and 3) append together 
loc i = 0
foreach event in `coefplot_events' {
	foreach lhs in at_pk at_kp any_helpr {
        use "`regsave_path'/`event'_`lhs'.dta", clear

        // add the columns
        gen event = "`event'"
        gen lhs = "`lhs'"

        // append to dataset
        if(`i' == 0){
            save "`regsave_path'/coefplot_estimates.dta", replace
        }
        else {
            append using "`regsave_path'/coefplot_estimates.dta"
            save "`regsave_path'/coefplot_estimates.dta", replace
        }
        sleep 500
        local i = `i' + 1
    }
}

gen t = 0 if var == "e0"
replace t = 1 if var == "a1"
save "`regsave_path'/coefplot_estimates.dta", replace

// use R file in same directory to actually make the plots

// Make the one by wealth 

loc coefplot_events "wneg2 any_rlost_job male_rwidowed fem_rwidowed any_rhosp any_disab any_health3to5"
/* loc regsave_path draft/JSresults/regsave */

// need to 1) grab estimates for each event-LHS combo 2) add columns and 3) append together 

loc i = 0
foreach event in `coefplot_events' {
	foreach lhs in at_pk at_kp any_helpr {
        foreach samp in lw hw {
            use "`regsave_path'/`event'_`lhs'_`samp'.dta", clear

            // add the columns
            gen event = "`event'"
            gen lhs = "`lhs'"
            gen samp = "`samp'"

            // append to dataset
            if(`i' == 0){
                save "`regsave_path'/coefplot_estimates_bywealth.dta", replace
            }
            else {
                append using "`regsave_path'/coefplot_estimates_bywealth.dta"
                save "`regsave_path'/coefplot_estimates_bywealth.dta", replace
            }
            sleep 500
            local i = `i' + 1
        }
    }
}

gen t = 0 if var == "e0"
replace t = 1 if var == "a1"
save "`regsave_path'/coefplot_estimates_bywealth.dta", replace